<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<!-- 引入主题样式 -->
<link href="themes/gray/easyui.css" rel="stylesheet">
<!-- 引入图标的样式 -->
<link href="themes/icon.css" rel="stylesheet">
<link href="css/main.css" rel="stylesheet">
<!-- 先引入jquery -->
<script type="text/javascript" src="js/jquery-1.7.2.js"></script>
<!-- 引入easyui -->
<script type="text/javascript" src="js/jquery-1.7.2.js"></script>
<script type="text/javascript" src="js/jquery.easyui.min.js"></script>
<script type="text/javascript" src="js/easyui-lang-zh_CN.js"></script>
<script type="text/javascript" src="js/jquery.etree.js"></script>
<script type="text/javascript" src="js/jquery.etree.lang.js"></script>
</head>
<script type="text/javascript">
	$(function() {
		$("#type").combobox({
			url:'getMaxNumerContent',
			valueField:'id',
			textField:'text'
		})
		
		$('#tt').etree({
			url : 'treeData',
			lines : true,
			animate : true,
			onLoadSuccess : function() {
				$(".tree-node").mouseover(function() {
					var $obj = $(this);
				});
			},
			//tree右键单击菜单

			onContextMenu : function(e, node) {
				e.preventDefault();
				// 查找节点

				var obj = $('#tt').tree('select', node.target);
				// 显示快捷菜单

				if (node.children == null || node.children.length == 0) {
					$('#tabsMenu1').menu('show', {
						left : e.pageX,
						top : e.pageY
					});
					//点击快捷菜单

					$("#tabsMenu1").menu({
						onClick : function(item) {
							if (item.id == 11) {//添加节点 

								$("#mydialog").show();
								$("#mydialog").dialog({
									title:'添加',
									collapsible: true,   
	                                minimizable: true,   
	                                maximizable: true, 
									buttons:[{
										text:'添加',
										handler:function(){
											var tid = node.id
											var tname = $("#newdom").val();
											$.ajax({
												url:'addType',      //发起添加节点请求

												type:'post',
												data:{'tid':tid,'tname':tname},
												success:function(){
													$('#mydialog').dialog('close'); 
													$("#newdom").textbox('setText','');
													$('#tt').tree('reload');
												}
											})
										}
									},  {
									   	 text:'取消',
									   	 handler:function(){
									   		$('#mydialog').dialog('close');
									   		$("#newdom").textbox('setText','');
									   	 }
									    }
									]
								})
							}else if(item.id == 12){
								$("#mydialog").show();
								$("#newdom").textbox('setText',node.text);
								$("#mydialog").dialog({
									title:'修改',
									collapsible: true,   
	                                minimizable: true,   
	                                maximizable: true, 
									buttons:[{
										text:'修改',
										handler:function(){
											var tid = node.id
											var tname = $("#newdom").textbox('getText');
											$.ajax({
												url:'changeType',      //发起修改节点请求

												type:'post',
												data:{'tid':tid,'tname':tname},
												success:function(){
													$('#mydialog').dialog('close');
													$("#newdom").textbox('setText','');
													$('#tt').tree('reload');
												}
											})
										}
									},  {
									   	 text:'取消',
									   	 handler:function(){
									   		$('#mydialog').dialog('close');
									   		$("#newdom").textbox('setText','');
									   	 }
									    }
									]
								})
							}else{
								$("#mydialog").show();
								$("#newdom").textbox('setText',"'"+node.text+"'");
								$("#newdom").textbox({
									readonly:true
								})
								$("#mydialog").dialog({
									title:'是否确认删除',
									collapsible: true,   
	                                minimizable: true,   
	                                maximizable: true, 
									buttons:[{
										text:'删除',
										handler:function(){
											var tid = node.id;
											$.ajax({
												url:'deleteType',      //发起删除节点请求
												type:'post',
												data:{'tid':tid},
												success:function(){
													$('#mydialog').dialog('close');
													$("#newdom").textbox('setText','');
													$('#tt').tree('reload');
													$("#newdom").textbox({
														readonly:false
													})
												}
											})
										}
									},  {
									   	 text:'取消',
									   	 handler:function(){
									   		$('#mydialog').dialog('close');
									   		$("#newdom").textbox('setText','');
									   		$("#newdom").textbox({
												readonly:false
											})
									   	 }
									    }
									]
								})
							}
						}
					})
				} else {
					$('#tabsMenu2').menu('show', {
						left : e.pageX,
						top : e.pageY
					});
					$("#tabsMenu2").menu({
						onClick : function(item) {
							if (item.id == 21) {//添加节点 

								$("#mydialog").show();
								$("#mydialog").dialog({
									title:'添加',
									collapsible: true,   
	                                minimizable: true,   
	                                maximizable: true, 
									buttons:[{
										text:'添加',
										handler:function(){
											var tid = node.id
											var tname = $("#newdom").val();
											$.ajax({
												url:'addType',      //发起添加节点请求

												type:'post',
												data:{'tid':tid,'tname':tname},
												success:function(){
													$('#mydialog').dialog('close'); 
													$("#newdom").textbox('setText','');
													$('#tt').tree('reload');
												}
											})
										}
									},  {
									   	 text:'取消',
									   	 handler:function(){
									   		$('#mydialog').dialog('close');
									   		$("#newdom").textbox('setText','');
									   	 }
									    }
									]
								})
							}else if(item.id == 22){
								$("#mydialog").show();
								$("#newdom").textbox('setText',node.text);
								$("#mydialog").dialog({
									title:'修改',
									collapsible: true,   
	                                minimizable: true,   
	                                maximizable: true, 
									buttons:[{
										text:'修改',
										handler:function(){
											var tid = node.id
											var tname = $("#newdom").textbox('getText');
											$.ajax({
												url:'changeType',      //发起修改节点请求

												type:'post',
												data:{'tid':tid,'tname':tname},
												success:function(){
													$('#mydialog').dialog('close');
													$("#newdom").textbox('setText','');
													$('#tt').tree('reload');
												}
											})
										}
									},  {
									   	 text:'取消',
									   	 handler:function(){
									   		$('#mydialog').dialog('close');
									   		$("#newdom").textbox('setText','');
									   	 }
									    }
									]
								})
							}
						}
					})
					
				}
			
			},
			onClick:function(node){
				$.ajax({
					url:'selectContentByCname',
					type:'post',
					data:{
						text:node.text
					},
					dataType:'json',
					success:function(data){
						if(data.selectContentMsg=="有"){
							$("#table").datagrid({
								url:'showContentByCname',
								pageSize:15,
								pageList:[15,20,25,50],
								pagination:true,
								pagePosition:'bottom',
								rownumbers:true,
								selectOnCheck:false,
								columns:[[    
									     {field:'cid',hidden:true},
									     {field:'',checkbox:true,width:100},    
									     {field:'ctitle',title:'知识标题',width:'20%'},    
									     {field:'cname',title:'知识类型',width:'20%'},    
									     {field:'ctime',title:'发布日期',width:'20%'},    
									     {field:'cstate',title:'状态',width:'20%'},    
									     {field:'operation',title:'操作',width:'20%'}    
									  ]],
								toolbar: [{
									  	iconCls: 'icon-edit',
									  	handler: function(){
									  		alert('编辑按钮')
									  		}
									  },'-',{
									  	iconCls: 'icon-help',
									  	handler: function(){
									  		alert('帮助按钮')
									  		}
									  }],
									  onDblClickRow:function(index,row){
											location.href="showContent?cid="+row.cid;
										}
								})
							}else{
								$.messager.confirm('消息','查询结果为空',function(r){    
								});  
							}
						}
				})
			}
		});

		$("#table").datagrid({
			url:'tableAll',
			pageSize:15,
			pageList:[15,20,25,50],
			pagination:true,
			pagePosition:'bottom',
			rownumbers:true,
			selectOnCheck:false,
			columns:[[    
			          {field:'cid',hidden:true},
			          {field:'',checkbox:true,width:100},    
			          {field:'ctitle',title:'知识标题',width:'20%'},    
			          {field:'cname',title:'知识类型',width:'20%'},    
			          {field:'ctime',title:'发布日期',width:'20%'},    
			          {field:'cstate',title:'状态',width:'20%'},    
			          {field:'operation',title:'操作',width:'20%'}    
			      ]],
			toolbar: [{
			  		iconCls: 'icon-edit',
			  		handler: function(){alert('编辑按钮')}
			  	},'-',{
			  		iconCls: 'icon-help',
			  		handler: function(){alert('帮助按钮')}
			  	}],
			    onDblClickRow:function(index,row){
					location.href="showContent?cid="+row.cid;
				}

		})
		$('#title').textbox({    
			height:30
		})
		$('#center').textbox({    
			height:30
		})
		$('#state').textbox({    
			height:30
		})
		//查询按钮
		$('#search').linkbutton({    
			width:50,
			onClick:function(){
				$("#ff").form('submit');
			}
		}); 
		$('#reset').linkbutton({    
			width:50,
			onClick:function(){
				$("#title").textbox("setText","");
				$("#center").textbox("setText","");
				$("#startDate").textbox("setText","");
				$("#endDate").textbox("setText","");
				$("#state").textbox("setText","");
				$("#table").datagrid({
					url:'tableAll',
					pageSize:15,
					pageList:[15,20,25,50],
					pagination:true,
					pagePosition:'bottom',
					rownumbers:true,
					selectOnCheck:false,
					columns:[[    
					          {field:'cid',hidden:true},
					          {field:'',checkbox:true,width:100},    
					          {field:'ctitle',title:'知识标题',width:'20%'},    
					          {field:'cname',title:'知识类型',width:'20%'},    
					          {field:'ctime',title:'发布日期',width:'20%'},    
					          {field:'cstate',title:'状态',width:'20%'},    
					          {field:'operation',title:'操作',width:'20%'}    
					      ]],
					toolbar: [{
					  		iconCls: 'icon-edit',
					  		handler: function(){alert('编辑按钮')}
					  	},'-',{
					  		iconCls: 'icon-help',
					  		handler: function(){alert('帮助按钮')}
					  	}],
					    onDblClickRow:function(index,row){
							location.href="showContent?cid="+row.cid;
						}

				})
			}
			
		}); 
		$('#btn').linkbutton({    
		    iconCls: 'icon-search'   
		});  
		
		//使用ajax方式提交查询条件
		$('#ff').form({    
		    url:'selectContent',  
		    type:'post',
		    dataType:'json',
		    success:function(data){ 
				var obj = eval("("+data+")");
				if(obj.searchMsg=="有"){
					$("#table").datagrid({
						url:'showContentBySearch',
						pageSize:15,
						pageList:[15,20,25,50],
						pagination:true,
						pagePosition:'bottom',
						rownumbers:true,
						selectOnCheck:false,
						columns:[[    
						          {field:'cid',hidden:true},
						          {field:'',checkbox:true,width:100},    
						          {field:'ctitle',title:'知识标题',width:'20%'},    
						          {field:'cname',title:'知识类型',width:'20%'},    
						          {field:'ctime',title:'发布日期',width:'20%'},    
						          {field:'cstate',title:'状态',width:'20%'},    
						          {field:'operation',title:'操作',width:'20%'}    
						      ]],
						toolbar: [{
						  		iconCls: 'icon-edit',
						  		handler: function(){
						  			alert('编辑按钮')
						  			}
						  	},'-',{
						  		iconCls: 'icon-help',
						  		handler: function(){
						  			alert('帮助按钮')
						  			}
						  	}],
						    onDblClickRow:function(index,row){
								location.href="showContent?cid="+row.cid;
							}

					})
				}else{
					$.messager.confirm('消息','查询结果为空',function(r){    
					});  
				}
		    }    
		}); 
		//增加知识内容的窗口
		$('#addContent').window({    
		    width:600,    
		    height:400,    
		    modal:true   
		}); 
		$("#addContent").window('close');
		
		$("#add").linkbutton({
			iconCls:'icon-add',
			onClick:function(){
				$("#addContent").window('open');
				//配置下拉列表
				$('#allTname').combobox({    
				    url:'selectAllTname',    
				    valueField:'id',    
				    textField:'text'   
				});
			}
		})
		$("#remove").linkbutton({
			iconCls:'icon-remove',
			onClick:function(){
				$("#delbox").dialog({
					title:'是否删除所选项',
					width:400,
					height:200,
					buttons:[{
						text:'确认',
						onClick:function(){
							var obj = $("#table").datagrid('getChecked');
							var list = new Array;
							for(var i=0;i<obj.length;i++)
								{
								list[i] = obj[i].cid;
								}
							$.ajax({
								url:'deletecontent',
								type:'post',
								data:{"list":list},
								success:function(data){
									$("#table").datagrid('reload')
									$("#delbox").dialog('close');
								}
							})
						}
					},{
						text:'取消',
						onClick:function(){
							$("#delbox").dialog('close');
						}
					}]
				})
				$("#delbox").show()
				
			}
		})
		
		//配置输入知识标题输入框
		$('#ctitle').textbox({    
		})
		//测试
		$('#btn1').linkbutton({    
		    iconCls: 'icon-search',
		    onClick:function(){
		    	$("#addFF").form('submit');
		    }
		});
		$('#addFF').form({    
		    url:'import',    
		    onSubmit: function(){    
		        // do some check    
		        // return false to prevent submit;    
		    },    
		    success:function(data){    
		        alert(data)    
		    }    
		});  
		
	});
	
	function import1(){
		var selectFile = document.getElementById("file").files[0];
		var reader = new FileReader();
		var text = reader.readAsText(selectFile);
		reader.onload = function(){
			document.getElementById("content").value=this.result;
		}
	}
</script>
<body class="easyui-layout">
	<div data-options="region:'west',title:'知识类型',split:true" style="width: 300px;background-image:url('picture/t.gif')">
		<ul id="tt"></ul>
	</div>
	<div data-options="region:'center',title:'center title'" style="padding: 5px; background: #eee;background-image:url('picture/t.gif')">
		<br>
		<form id="ff" method="post"> 
			知识标题：<input id="title" name="title" type="text" style="width:280px;background-color:#ffffff;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
			知识内容：<input id="center" name="center" type="text" style="width:280px"><br>
			发布日期：<input id="startDate" name="startDate" type="text" class="easyui-datebox" style="width: 136px;height: 30px;"></input>
			-<input id="endDate" name="endDate" type="text" class="easyui-datebox" style="width: 137px;height: 30px"></input>
			&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
			状态：<input id="state" name="state" type="text" style="width:280px">
			&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a id="search" href="#">查询</a>  
			&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a id="reset" href="#">重置</a><br><br>
			<a id="add" href="#">增加</a> 
			<a id="remove" href="#">删除</a>
			<br> 
			<hr>
			<table id="table"></table> 
		</form>
	</div>
	<div id="tabsMenu1" class="easyui-menu" style="width: 120px;">
		<div id="11">添加</div>
		<div id="12">修改</div>
		<div id="13">删除</div>
	</div>
	<div id="tabsMenu2" class="easyui-menu" style="width: 120px;">
		<div id="21">添加</div>
		<div id="22">修改</div>
	</div>
	<div id="mydialog" style="display: none;">
		<div align="center" style="margin-top: 5%">
			<input id="newdom" type="text" class="easyui-textbox" data-options="width:300">
		</div>
	</div>
	
	<div id="addContent" align="center">
		<br>
		<hr>
		<form action="import" method="post">
					<div style="margin-top: 5%;">
						知识标题:<input type="text" class="easyui-textbox" style="width: 300;" name="title">
					</div>
					<div style="margin-top: 3%">
						知识摘要:<input type="text" class="easyui-textbox" style="width: 300:" name="abstract">
					</div>
					<div style="margin-top: 3%">
						所属类型:<input id="type" class="easyui-combobox" name="type" style="width: 300;">
					</div>
					<div style="margin-top: 3%">
						知识内容:<input id="file" type="file" onchange="import1()" style="width: 300;">
								<input id="content" type="hidden" name="files" value="">
					</div>
					<div style="margin-top: 3%">
						所属专题:<input type="text" name="special" style="width: 300;">
					</div>
					<div style="margin-top: 3%">
						<button type="submit">确认</button>
					</div>
				</form>
	</div>  
	<div id="delbox" >
		<div align="center" style="margin-top: 5%;"><span style="font-size: 20px;">是否确认删除所选项！</span></div>
	</div>
	<script type="text/javascript">
		function update(obj){
			$.ajax({
				url:'updateContent',
				type:'post',
				data:{
					cid:obj.id 

				},
				success:function(data){
					//配置下拉列表
					$('#allTname').combobox({    
					    url:'selectAllTname',    
					    valueField:'id',    
					    textField:'text'   
					});
					$("#win").window('open');
					
				}
			})
		}
		function delet(obj){
			$.messager.confirm('确认','您确认想要删除记录吗？',function(r){    
			    if (r){    
			    	$.ajax({
						url:'updateContentState',
						type:'post',
						data:{
							cid:obj.id 

						},
						success:function(data){
							var obj = eval("("+data+")");
							if(obj.updateContentStateMsg=='成功'){
								$.messager.confirm('确认','删除成功',function(r){    
								});
								$("#table").datagrid('reload');
							}
						}
					})
			    }    
			});
		}
	</script>
	
</body>
</html>